/**
 * 实时盘口管理初始化
 */
var Realtime = {
    id: "RealtimeTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Realtime.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '代码', field: 'gScode', visible: true, align: 'center', valign: 'middle'},
            {title: '名称', field: 'gName', visible: true, align: 'center', valign: 'middle'},
            {title: '类型', field: 'gType', visible: true, align: 'center', valign: 'middle'},
            {title: '类型描述', field: 'gDec', visible: true, align: 'center', valign: 'middle'},
            {title: '操作时间', field: 'gTime', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Realtime.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Realtime.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加实时盘口
 */
Realtime.openAddRealtime = function () {
    var index = layer.open({
        type: 2,
        title: '添加实时盘口',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/realtime/realtime_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看实时盘口详情
 */
Realtime.openRealtimeDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '实时盘口详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/realtime/realtime_update/' + Realtime.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除实时盘口
 */
Realtime.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/realtime/delete", function (data) {
            Feng.success("删除成功!");
            Realtime.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("realtimeId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询实时盘口列表
 */
Realtime.search = function () {
    var queryData = {};
    queryData['gScode'] = $("#gScode").val();
    queryData['gTime'] = $("#gTime").val();
    queryData['gType'] = $("#gtype").val();
    Realtime.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Realtime.initColumn();
    table = new BSTable(Realtime.id, "/realtime/list", defaultColunms);
    table.setPaginationType("server");
    Realtime.table = table.init();
});
var table;
